local RSNG = RSNG
local AceOO = AceLibrary("AceOO-2.0")
local C = RSNG.Classes

local StatusBarInfo = AceOO.Class(C.IStatusBarInfo, C.ISerializable)
StatusBarInfo.virtual = true

function StatusBarInfo.prototype:init()
	StatusBarInfo.prototype.parent.init(self)
	self.text = nil
	self.format = nil
	self.red = nil
	self.green = nil
	self.blue = nil
end

function StatusBarInfo.prototype:GetText()
	return self.text or self:GetDefaultText()
end

function StatusBarInfo.prototype:GetTextFormat()
	return self.format or self:GetDefaultTextFormat()
end

function StatusBarInfo.prototype:GetColor()
	local r = self.red
	if r then
		return r, self.green, self.blue
	else
		return self:GetDefaultColor()
	end
end

function StatusBarInfo.prototype:GetOptionTable()
	local t = self.options
	if not t then
		t = {
			name = "Status bar",
			type = "group",
			args = {
				text = {
					type = "text",
					name = L["Text"],
					desc = L["Left text."],
					get = function () return self.text end,
					set = function (value) self.text = value end,
				},
				format = {
					type = "text",
					name = L["Text Format"],
					desc = L["Right text format string."],
					get = function () return self.format end,
					set = function (value) self.format = value end,
				},
				color = {
					type = "color",
					name = L["Color"],
					desc = L["Color of the status bar."],
					get = function () return self.red, self.green, self.blue end,
					set = function (r, g, b) self.red, self.green, self.blue = r, g, b end,
				},
				filter = self:GetFilterOptionTable(),
			}
		}
		self.options = t
	end
	return t
end

function StatusBarInfo.prototype:Serialize(type, data)
	if type == "save" then
		data.text = self.text
		data.format = self.format
		data.red = self.red
		data.green = self.green
		data.blue = self.blue
		local f = {}
		self:FilterSerialize("save", f)
		data.filter = f
	elseif type == "load" then
		self.text = data.text
		self.format = data.format
		self.red = data.red
		self.green = data.green
		self.blue = data.blue
		local f = data.filter
		if f then
			self:FilterSerialize("load", f)
		end
	end
end

function StatusBarInfo.prototype:SetStatusBar(bar)
	if self.sb ~= bar then
		self.sb = bar
		bar:SetInfo(self)
	end
end

C.BaseStatusBarInfo = StatusBarInfo

local StatusBarInfo = AceOO.Class(C.BaseStatusBarInfo, C.ISerializable)
StatusBarInfo.virtual = true

function StatusBarInfo.prototype:init()
	StatusBarInfo.prototype.parent.init(self)
	self.filter = C.ListFilter:new()
end

function StatusBarInfo.prototype:FilterSerialize(...)
	return self.filter:Serialize(...)
end

function StatusBarInfo.prototype:GetFilterOptionTable()
	return self.filter:GetOptionTable()
end

function StatusBarInfo.prototype:SetStatusBar(bar)
	if self.sb ~= bar then
		self.sb = bar
		bar:SetInfo(self)
	end
end

C.FilteredStatusBarInfo = StatusBarInfo

